﻿using System;
using EzDesk.Apps.Interface.Attendance;
using EzDesk.Apps.ServiceImpl.Attendance;
using EzDesk.Utility.TimerService;
using EzDesk.Utility.Web.ServiceReference;

namespace EzDesk.Clients.DesktopWeb.TimerTask
{
    class DailyAttendanceReportTask : EverydayTimerTask
    {
        private readonly IAttendanceService _attendanceService = new AttendanceService();
        IAttendanceService AttendanceService
        {
            get { return _attendanceService; }
        }

        public DailyAttendanceReportTask()
            : base("DailyAttendanceReportTask")
        {
            DayExecuteTime = GetSendTime();
        }

        protected override void doExecute()
        {
            AttendanceService.SendDailyAttendanceReport();
        }
        

        public TimeSpan GetSendTime()
        {
            var attendanceConfig = AttendanceService.GetAttendanceConfig().Result;
            return attendanceConfig.StdOnDutyTime.ToDateTime().Add(-attendanceConfig.OnDutyOffsetForward).TimeOfDay.Add(TimeSpan.FromSeconds(5));
        }

    }
}
